package daily.year2024.m8;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wjs 2024/8/7
 */
public class d7 {
    //第一题：分糖果问题
    class Solution {
        public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
            int n = candies.length;
            List<Boolean> list = new ArrayList<>();
            int max = 0;
            for(int i=0;i < n;i++) {
                max = Math.max(candies[i],max);
            }
            for(int i=0;i < n;i++) {
                if(candies[i] + extraCandies >= max) {
                    list.add(true);
                } else {
                    list.add(false);
                }
            }
            return list;
        }
    }

    //第二题：插花问题
    class Solution2 {
        public boolean canPlaceFlowers(int[] flowerbed, int n) {
            int m = flowerbed.length;
            boolean flag = true;
            for(int i=0;i < m;i++) {
                if(flag && flowerbed[i] == 0 && n > 0) {
                    n--;
                    flag = false;
                    flowerbed[i] = 1;
                    continue;
                }
                if(flowerbed[i] == 1) {
                    //补偿操作
                    if(i > 0 && flowerbed[i-1] == 1) {
                        n++;
                    }
                    flag = false;
                } else {
                    flag = true;
                }
            }
            return n == 0;
        }
    }
}
